package com.mi.fastbird.common.spring.interceptor;

import com.mi.fastbird.common.util.project.MiException;
import com.mi.fastbird.common.util.project.SRS;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.Arrays;
import java.util.List;


/**
 * 全局异常处理
 *
 * @author 王永吉
 * @date 2019/6/27 8:44
 */
@Slf4j
@RestControllerAdvice
public class ExceptionInterceptor {
    private static List<Integer> a = Arrays.asList(401, 4011);

    /**
     * 非编码人员抛出的异常
     */
    @ExceptionHandler(value = Exception.class)
    public SRS exceptionHandler(Exception ex) {
        ex.printStackTrace();
//        log.error(ExceptionUtils.getStackTrace(ex));
        return SRS.byError("操作失败 请稍后重试");
    }

    /**
     * 编码人员主动抛出的异常
     */
    @ExceptionHandler(value = MiException.class)
    public SRS miExceptionHandler(MiException ex) {
        ex.printStackTrace();
//        log.error(ex.getMiSRSesponse().toString());
        return ex.response();
    }
}
